/**
 * create by zy 88377761
 */
package com.example.demo.util;

import java.util.List;
import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author 88377761
 *
 */
public class DataOperUtil {
	private static final Logger LOGGER = LoggerFactory.getLogger(DataOperUtil.class);

	/**
	 * 分批操作
	 * 
	 * @param list
	 * @param size
	 * @param function
	 *            create by zy 88377761
	 */
	public void operBySize(List<?> list, Integer size, Function function) {
		Integer length = list.size();
		if (length > size) {
			function.operMethod(list.subList(0, size));
			operBySize(list.subList(size, length), size, function);
		} else {
			function.operMethod(list);
		}
	}



	public void getResult(List<Future<?>> resultList) {
		// 遍历任务的结果
		for (Future<?> fs : resultList) {
			try {
				fs.get(); // 各个线程（任务）执行的结果
			} catch (Exception e) {
				LOGGER.error(fs.toString(), e);
			}
		}
	}

	public interface Function {
		void operMethod(List<?> list);
	}
}
